<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>sessionStorage示例</title>
</head>

<body>

    <input type="text" id="field">

    <script>
        let field = document.getElementById('field')

        //检测是否存在 autosave 键值
        if (sessionStorage.getItem('autosave')) {
            field.value = sessionStorage.getItem('autosave');
        }

        //监听文本框chaneg事件
        field.addEventListener("change", function () {
            //保存内容到sessionStorage
            sessionStorage.setItem("autosave", field.value);
        })
    </script>
</body>

</html>